<?php

require_once dirname(__FILE__).'/../lib/empleadosGeneratorConfiguration.class.php';
require_once dirname(__FILE__).'/../lib/empleadosGeneratorHelper.class.php';

/**
 * empleados actions.
 *
 * @package    gescell
 * @subpackage empleados
 * @author     Your name here
 * @version    SVN: $Id: actions.class.php 12474 2008-10-31 10:41:27Z fabien $
 */
class empleadosActions extends autoEmpleadosActions
{
    public function executeEdit(sfWebRequest $request){
        $criteria = new Criteria();
        $guard_user =  $this->getUser()->getGuardUser()->getId();
        if ($request->hasParameter('id_guar')){
            $id = $request->getParameter('id_guar');
            if($guard_user == $id){
                $criteria->add(empleadosPeer::SF_GUARD_USER,$guard_user);
            }
            else
               $criteria->add(empleadosPeer::SF_GUARD_USER,$id);
        }
        else{$criteria->add(empleadosPeer::SF_GUARD_USER,$guard_user);}

        //
        //$this->empleados = new empleados();
        $this->empleados = empleadosPeer::doSelectOne($criteria);
        if($this->getRequest()->hasParameter('ver')&& !$this->empleados){
            $this->redirect('empleados/mensaje?mensaje=El perfil del Usuario no se a Creado Aun');
        }
        if (!$this->empleados) {
            //$this->form = new empleadosForm($this->empleados);
            //$this->form->setDefault('sf_guard_user',2 );
            $this->redirect('empleados/new?sfGuardid='.$guard_user);
        }
        else{
            $this->form = new empleadosForm($this->empleados);
            //$this->form->setDefault('sf_guard_user',$guard_user );
        }
    }
    public function executeNew(sfWebRequest $request)
    {
       $guard_user =  $request->getParameter('sfGuardid');
       $this->form = $this->configuration->getForm();
       $this->empleados = $this->form->getObject();
       $this->form->setDefault('sf_guard_user',$guard_user );
     }
     public function executeMensaje(){
         $this->mensaje = $this->getRequest()->getParameter('mensaje');
     }
}
